'use strict';

let request = require('supertest');
let should = require('should');

describe('User', function () {
    let token = '';
    let open_id = '';
    before(function(done) {
        request('http://39.106.132.95:2001').post('/api/users/login')
            .set('Accept', 'application/json')
            .send({
                'email': 'fengxuting@qq.com',
                'password': '14e1b600b1fd579f47433b88e8d85291',
            })
            .expect('Content-Type', /json/)
            .expect(200)
            .end(function(err, res) {
                if (err) done(err);
                res.body.should.have.property('open_id');
                res.body.open_id.should.equal('whZc2bPVjbgHY0KPNp9Cfw==');
                token = res.body.access_token;
                open_id = res.body.open_id;
                done();
            });
      });
    it('User find', function (done) {
        request('http://39.106.132.95:2001').get('/api/users/findByOpenId')
        .set('Accept', 'application/json')
        .set('authorization', 'Bearer ' + token)
        .send({
                'open_id': open_id
            })
            .expect('Content-Type', /json/)
            .expect(200)
            .end(function(err, res) {
                if (err) done(err);
                res.body.should.have.property('nickname');
                res.body.nickname.should.equal('frank');
                console.log(res.body.nickname);
                done();
            });
    });
});
